//
//  TCUTree.h
//  TreeMenuTest
//
//  Created by Etienne on 23/06/07.
//  Copyright (c) 2007 Etienne Samson. All rights reserved.
//

#import <Cocoa/Cocoa.h>
#import <CoreFoundation/CoreFoundation.h>

#define TreePasteboardType @"TCUTreePasteboardType"

@interface TCUTree : NSObject <NSCopying, NSCoding> {
//    void* DONOTMODIFY;
}

/*" Creating Trees "*/
+ (id) treeWithObject:(id) object;
+ (id) treeWithContentsOfFile:(NSString*)file;

- (id) initWithObject:(id) object;
- (id) initWithDictionary:(NSDictionary*)dict;
- (id) initWithFile:(NSString*)file;

/*" Accessing referenced objects "*/
- (id) object;

/*" Looking 'up the tree' "*/
- (TCUTree*) root;
- (TCUTree*) parent;

/*" Access to child trees "*/
- (NSEnumerator*) childEnumerator;

- (unsigned) childCount;
- (TCUTree*) firstChild;
- (TCUTree*) lastChild;
- (TCUTree*) childAtIndex: (unsigned) index;
- (NSArray*) children;

- (BOOL) containsChild: (TCUTree*) child recurse:(BOOL)recurse;
- (unsigned) indexOfChild: (TCUTree*) child;

/*" Recursive access to child trees "*/
- (TCUTree*) subtreeContainingObject:(id)object;

/*" Access to sibling trees "*/
- (TCUTree*) previousSibling;
- (TCUTree*) nextSibling;

/*" Mutating access "*/
- (void) addChild: (TCUTree*) child;
- (void) addChild: (TCUTree*) child atIndex: (unsigned) index;
- (void) removeChild: (TCUTree*) child;
- (void) removeChildAtIndex: (unsigned) index;
- (void) removeAllChildren;

- (void) prependSibling: (TCUTree*) sibling;
- (void) appendSibling: (TCUTree*) sibling;

/*" Grafting and pruning "*/
- (void) graftOntoTree: (TCUTree*) tree;
- (void) graftOntoTree: (TCUTree*) tree atIndex: (unsigned) index;
- (void) prune;

/*" Other stuff "*/
- (BOOL) isLeaf;
- (BOOL) writeToFile:(NSString*)file  atomically:(BOOL)atomically;

@end
